package nongchang.kuaijiecaifu.com.ncapp_android.ui.fragment;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import nongchang.kuaijiecaifu.com.ncapp_android.R;
import nongchang.kuaijiecaifu.com.ncapp_android.common.fragment.BaseFragment;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.good.Integral;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.main.Follow;
import nongchang.kuaijiecaifu.com.ncapp_android.ui.adapter.FollowAdapter;
import nongchang.kuaijiecaifu.com.ncapp_android.ui.adapter.IntegralAdapter;
import nongchang.kuaijiecaifu.com.ncapp_android.ui.widget.LoadingLayout;
import nongchang.kuaijiecaifu.com.ncapp_android.ui.widget.OnLoadeMoreListener;

/**
 * Created by Administrator on 2016/3/11 0011.
 */
public class FollowFragment extends BaseFragment {
    @BindView(R.id.refresh)
    SwipeRefreshLayout mRefresh;
    @BindView(R.id.list)
    RecyclerView mListView;
    @BindView(R.id.loading)
    LoadingLayout mLoading;
    OnLoadeMoreListener mLoadMore = new OnLoadeMoreListener() {
        @Override
        public void onLoadMore(int page) {

        }
    };
    private FollowAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_follow, container, false);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ButterKnife.bind(this, getView());
        mListView.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new FollowAdapter(getContext());
        mListView.setAdapter(adapter);
        mListView.addOnScrollListener(mLoadMore);
        mRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mRefresh.setRefreshing(true);
            }
        });
        load();
    }

    private void load() {
        List<Follow> list = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            Follow item = new Follow();
            item.content = "我是商家留言";
            item.title = "我就是标题";
            item.image = "http://banbao.chazidian.com/uploadfile/2016-01-25/s145368924044608.jpg";
            list.add(item);
        }
        mLoading.showContent();
        adapter.update(list);
    }
}
